histogram: add pow2 allocation stats via MIMALLOC_SHOW_HISTOGRAM=1#529
histogram: add pow2 allocation stats via MIMALLOC_SHOW_HISTOGRAM=1#529larkmjc wants to merge 4 commits intomicrosoft:devfrom
Conversation
src/stats.c
Outdated
|
|
||
| void _mi_histogram_log(size_t size) | ||
| { | ||
| size_t bucket = MI_SIZE_BITS - 1 - mi_clz(size); |
There was a problem hiding this comment.
Why not using mi_bsr? That is,
if (mi_unlikely(size == 0)) return;
size_t bucket = mi_bsr(size);There was a problem hiding this comment.
Good idea. I have made these two changes. I think your suggestion for the zero check is necessary unless we were to add another element to the histogram array which also would eliminate a branch. I do a null check in the caller but didn't consider not null pointers with zero size but I believe it does happen when debug is disabled after looking at this conditional statement in mi_heap_malloc_small:
Lines 77 to 81 in 38a0322
There was a problem hiding this comment.
I appreciate the feedback from @michaeljclark. Last year, I was exploring mimalloc performance issues using the preliminary work. Thus, my proposed change was the part of the workbench.
otherwise we end up printing a title without any histogram if stats are not enabled.
|
Interesting pr; just based it on top of |
I do not intend this pull to be merged, but am surfacing the feature just in case anyone finds it useful. It is a bit easier to read if one is trying to assess allocation sizes with a power of two granularity. It is currently guarded behind
#ifdef MI_STAT>1but#if MI_DEBUG>0might be more appropriate. It currently adds an atomic_increment to counters in a shared histogram array. It could be changed to use thread-local arrays that are merged at program termination.